<!DOCTYPE html>
<html>
<head>
    <title>楼盘销控展示</title>
    <meta charset="utf-8">
    <link rel="stylesheet" href="/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/style/admin.css" media="all">
    <link rel="stylesheet" href="/style/jmdf.css" media="all">
    <style>
        .footer {
            color: inherit;
            border: 1px solid #e7eaec;
            background: #f5f5f6;
            padding: 5px;
            width: 100%;
            position: fixed;
            bottom: 0px;
            text-align: center;
        }
    </style>
</head>
<body>
<div class="layui-fluid">
    <h1 style="text-align: center;">请选择要展示的征收项目[<span class="jmdf-color-red">楼盘销控展示</span>]</h1>
    <form class="layui-form" id="contractForm" style="margin-top: 10px;">
        <div class="layui-row layui-col-space15">
            <div class="layui-col-md8">
                <div class="layui-card">
                <#if (townMap?? && zsProjectMap??)>
                    <#list townMap?keys as town>
                        <#if (zsProjectMap[town]??)>
                            <#assign zsProjectList=zsProjectMap[town]/>
                            <div class="layui-card-header" style="font-size: 20px;font-weight: bold;">${(townMap[town])!}</div>
                            <div class="layui-card-body">
                                <#list zsProjectList as zsProject>
                                    <input type="checkbox" name="zsProjectId" value="${(zsProject.id)!}" title="${(zsProject.projectName)!}" lay-skin="primary" lay-filter="filter"/>
                                </#list>
                            </div>
                        </#if>
                    </#list>
                </#if>
                </div>
            </div>
            <div class="layui-col-xs4">
                <div class="layui-card">
                    <div class="layui-card-header jmdf-color-red" style="font-size: 20px;font-weight: bold;">项目所分配安置项目</div>
                    <div class="layui-card-body" id="azProjectInfo"></div>
                </div>
            </div>
        </div>
    </form>
    <div class="footer">
        <button type="button" class="layui-btn" name="submitBtn" id="submitBtn">提　　交</button>
    </div>
</div>
</body>
<script src="/layui/layui.js" charset="utf-8"></script>
<script>
    layui.config({
        base: '/modules/' //静态资源所在路径
    }).use(['jquery', 'form','jmdf','layer'], function () {
        var $ = layui.jquery, jmdf = layui.jmdf, form = layui.form, layer = layui.layer;

        $("#submitBtn").click(function(){
            var zsProjectIdStr = zsProjectCheck();
            var azProjectIdStr = azProjectCheck();
            if (zsProjectIdStr == ""){
                layer.msg("请先选择要公示的征收项目！", {anim: 6, icon: 2, time: 3000});
            }else if (azProjectIdStr == ""){
                layer.msg("请先选择要公示的安置项目！", {anim: 6, icon: 2, time: 3000});
            }else{
                window.open("houseShow?zsProjectIdStr="+zsProjectIdStr+"&azProjectIdStr="+azProjectIdStr);
            }
        });

        //监听checkbox按钮，随时触发改变PDF链接
        form.on('checkbox(filter)', function(data){
            $("#azProjectInfo").html("加载中...");
            var zsProjectIdStr = zsProjectCheck();
            $.get("getAzProjectListByZsProjectIdStr",{
                zsProjectIdStr:zsProjectIdStr
                ,_time:new Date().getTime()
            },function(data){
                var azProjectInfo = "";
                if (data.code == "0001"){
                    var azProjectList = data.data;
                    var azProjectListLen = azProjectList == null ? 0 : azProjectList.length;
                    if (azProjectListLen > 0){
                        for (var i = 0;i < azProjectListLen;i++){
                            var azProject = azProjectList[i];
                            azProjectInfo += "<input type='checkbox' name='azProjectId' value='"+ azProject.id +"' title='"+ azProject.projectName +"' lay-skin='primary'/>"
                        }
                    }
                }
                $("#azProjectInfo").html(azProjectInfo);
                //渲染一下，将数据显示
                form.render();
            })
        });

        //获取选中的征收项目id
        function zsProjectCheck(){
            var zsProjectIdStr = "";
            $("input:checkbox[name='zsProjectId']:checked").each(function(){
                zsProjectIdStr += $(this).val() + ",";
            });
            var zsProjectIdStrLength = zsProjectIdStr.length;
            if (zsProjectIdStrLength > 0){
                zsProjectIdStr = zsProjectIdStr.substring(0,zsProjectIdStrLength-1);
            }
            return zsProjectIdStr;
        }

        //获取选中的安置项目id
        function azProjectCheck(){
            var azProjectIdStr = "";
            $("input:checkbox[name='azProjectId']:checked").each(function(){
                azProjectIdStr += $(this).val() + ",";
            });
            var azProjectIdStrLength = azProjectIdStr.length;
            if (azProjectIdStrLength > 0){
                azProjectIdStr = azProjectIdStr.substring(0,azProjectIdStrLength-1);
            }
            return azProjectIdStr;
        }
    })
</script>
</html>